package handler

import (
	"context"
	"ser-server/basic/config"
	"ser-server/internal/model"
	"ser-server/proto/video"
)

type VideoServer struct {
	video.UnimplementedVideoServer
}

func (v *VideoServer) ListVideo(_ context.Context, req *video.ListVideoReq) (*video.ListVideoResp, error) {
	var listVideo []*model.Video
	offset := (req.Page - 1) + req.PageSize
	config.DB.Offset(int(offset)).Where(int(req.PageSize)).Order("created_at Desc").Find(&listVideo)
	var List []*video.ListVideo
	for _, l := range listVideo {
		List = append(List, &video.ListVideo{
			Title:             l.Title,
			NikeName:          l.NikeName,
			LikeCount:         float32(l.LikeCount),
			NumberCollections: l.NumberCollections,
		})
	}
	return &video.ListVideoResp{
		List: List,
	}, nil
}
